package com.dhq.myapp.util.dialog

import android.content.Context
import com.dhq.myapp.util.dialog.listener.DialogListener
import com.lxj.xpopup.enums.PopupAnimation

import com.dhq.myapp.util.dialog.DialogUtils


/**
 * DESC
 * Created by admin on 2019/8/26.
 */
class DialogBuilder(val context: Context?) {
    /*
      标题
       */
    var title: String? = null
        private set

    /*
   内容
    */
    var content: String? = null
        private set

    /*
   内容文字颜色
    */
    var contentColor: Int = 0

    /*
   确定文字
    */
    var comfirmText: String? = null
        private set

    /*
   取消文字
    */
    var cancleText: String? = null
        private set

    /*
   触摸背景消失
    */
    var isCanDismiss: Boolean = true
        private set

    /*
   物理返回建消失
    */
    var isBackPressedDismiss: Boolean = true
        private set

    /*
   自动打开键盘
    */
    var isAutoOpenSoftInput: Boolean = false
        private set

    /**
     * 设置弹框动画
     * @param popupAnimation
     */
    /*
        动画模式
         */
    var popupAnimation: PopupAnimation? = null

    /**
     * 自定义布局
     */
    var layoutId: Int = 0
        private set

    /**
     * 自定义布局解析器
     */
    private var convert: DialogConvert? = null


    private var mComfirmListener: DialogListener? = null
    private var mCancleListener: DialogListener? = null

    /**
     * 设置标题
     * @param title
     * @return
     */
    fun setTitle(title: String?): DialogBuilder {
        this.title = title
        return this
    }

    /**
     * 设置文本内容
     * @param content
     * @return
     */
    fun setContent(content: String?): DialogBuilder {
        this.content = content
        return this
    }

    /**
     * 设置文本内容
     * @param content
     * @return
     */
    fun setContent(content: String?, contentColor: Int): DialogBuilder {
        this.content = content
        this.contentColor = contentColor
        return this
    }


    /**
     * 是否可以消失
     * @return
     */
    fun setCanDismiss(canDismiss: Boolean): DialogBuilder {
        isCanDismiss = canDismiss
        return this
    }

    /**
     * 是否返回消失
     * @return
     */
    fun setBackPressedDismiss(backPressedDismiss: Boolean): DialogBuilder {
        isBackPressedDismiss = backPressedDismiss
        return this
    }

    val comfirmListener: DialogListener?
        get() = mComfirmListener

    /**
     * 设置弹框确认按钮文字及事件
     * @return
     */
    fun setComfirmListener(comfirmText: String?, comfirmListener: DialogListener?): DialogBuilder {
        this.comfirmText = comfirmText
        this.mComfirmListener = comfirmListener
        return this
    }

    val cancleListener: DialogListener?
        get() = mCancleListener

    /**
     * 设置弹框取消按钮文字及事件
     * @return
     */
    fun setCancleListener(cancleText: String?, cancleListener: DialogListener?): DialogBuilder {
        this.cancleText = cancleText
        this.mCancleListener = cancleListener
        return this
    }


    fun setAutoOpenSoftInput(autoOpenSoftInput: Boolean): DialogBuilder {
        this.isAutoOpenSoftInput = autoOpenSoftInput
        return this
    }

    /**
     * 设置自定义弹框布局
     * @param layoutId
     * @param convert
     * @return
     */
    fun setLayoutId(layoutId: Int, convert: DialogConvert?): DialogBuilder {
        this.layoutId = layoutId
        this.convert = convert
        return this
    }

    fun getConvert(): DialogConvert? {
        return convert
    }


    fun bulid(): DialogUtils {
        return DialogUtils(this)
    }
}